<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,
        body {
            height: 800%;
            /* 要有足够高度去测试滚动 */
        }
    </style>

</head>

<body>

    <script>
        const throttle = (fn, time) => {
            let flag = true;
            return function () {
                if (flag) {
                    flag = false;
                    setTimeout(() => {
                        fn.apply(this);
                        flag = true
                    }, time)
                }
            }
        }
        document.onscroll = throttle(() => {
            console.log('触发滚动函数');
        }, 2000)
    </script>
</body>

</html>